<?php
class category_model extends CI_Model{
    protected $_table = 'mock_categories';
    public function __construct(){
        parent::__construct();

    }
    public function listCate_product(){
        return $this->db->get($this->_table)->result_array();
    }
    public function list_cate(){
        return $this->db->get($this->_table)->result_array();
    }
    public function totalCategory(){
        return $this->db->count_all($this->_table);
    }
    public function listCategory($off,$start){
        $this->db->limit($off,$start);
        return $this->db->get($this->_table)->result_array();
    }
    public function cate_move($id){
        if($id != ''){
            $this->db->where('cate_id !=',$id);
        }
        return $this->db->get($this->_table)->result_array();
    }
    public function getdata($id){
        $this->db->where("cate_id",$id);
        return $this->db->get($this->_table)->row_array();
    }
    public function checkName($name){
        $this->db->where("cate_name",$name);
        $numName = $this->db->count_all_results($this->_table);
        if($numName >0){
            return FALSE;
        }else{
            return TRUE;
        }
    }
    public function checkName_update($id,$name){
        if($id != ""){
            $this->db->where("cate_id !=",$id);
        }
        $this->db->where("cate_name",$name);
        $numName = $this->db->count_all_results($this->_table);
        if($numName >0){
            return FALSE;
        }else{
            return TRUE;
        }
    }
    public function addCategory($data){
        return $this->db->insert($this->_table,$data);
    }
    public function update($id,$data){
        $this->db->where("cate_id",$id);
        $this->db->update($this->_table,$data);
    }
    public function deleteCategory($id){
        $this->db->delete($this->_table,array('cate_id'=>$id));
    }
}

